{% extends 'base_children.html' %}

{% block content %}
    <div class="layui-row larryms-panel auth-user-add">
     <form action="{% url 'api_idc' %}" class="layui-form layui-form-pane" method="PUT" id="demoAddForm">
{#            {% csrf_token %}#}
        <input name="id" value="{{ data.id }}" type="hidden">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">机房名称</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="name" value="{{ data.name }}" lay-verify="required" placeholder="请输入用户名"
                                   type="text">
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">机房地址</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="address" value="{{ data.address |default_if_none:''}}" placeholder="请输入地址" type="text">
                    </div>
                </div>
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="tel" value="{{ data.tel |default_if_none:''}}" placeholder="请输入电话" type="text">

                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">客户经理</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="contact" value="{{ data.contact |default_if_none:''}}" placeholder="经理名字" type="text">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">手机</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="contact_phone" value="{{ data.contact_phone |default_if_none:'' }}" lay-verify="phone" placeholder="请输入手机"
                                   type="text">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">机柜</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="jigui" value="{{ data.jigui |default_if_none:''}}" placeholder="机柜" type="text">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">IP范围</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="ip_range" value="{{ data.ip_range|default_if_none:'' }}" placeholder="IP范围" type="text">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">接入带宽</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="bandwidth" value="{{ data.bandwidth |default_if_none:''}}" placeholder="带宽" type="text">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">起租日</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="start_date"  id="start_date"  lay-verify="required" type="text">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">到期日</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="end_date" lay-verify="required" id="end_date" type="text">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">费用</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="cost" value="{{ data.cost|default_if_none:'' }}" placeholder="金额" type="text">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                       <label class="layui-form-label">机房类型</label>
                    <div class="layui-input-block">
                        <select name="type">
                            <option value="{{ data.type }}"> {{ data.get_type_display }}</option>
                            <option value="自建">自建</option>
                            <option value="电信">电信</option>
                            <option value="联通">联通</option>
                            <option value="移动">移动</option>
                            <option value="BGP" >BGP</option>
                        </select>

                    </div>
                    </div>

                </div>
                <div class="larryms-layer-btn " >
                    <a class="layui-btn layui-btn layui-btn-sm " lay-submit="" lay-filter="demoadd" id="submitAdd">提交</a>

                    <a class="layui-btn layui-btn layui-btn-sm  layui-btn-danger" id="closeAdd">关闭</a>
                </div>


            </form>
        </div>

{% endblock %}
{% block self_foot %}
<script type="text/javascript">
    layui.config({
        version: "2.0.8",
        base: '/static/larryms/',
        layertype:2
    }).extend({
        larry: 'js/base'
    }).use(['jquery','larry','layer','larryms','form','laydate'], function() {
           var $ = layui.$,
            larry = layui.larry,
            table = layui.talbe,
            larryms = layui.larryms,
            form = layui.form,
            laydate = layui.laydate;
        var curIfr = parent.layer.getFrameIndex(window.name);

        $('#closeAdd').on('click', function() {
            parent.layer.close(curIfr);
        });
        laydate.render({
        elem: '#start_date'
        ,value: '{{ data.start_date|date:'Y-n-d' }}', format:'yyyy-MM-dd', isInitValue:true
        });
        laydate.render({
        elem: '#end_date'
        ,value: '{{ data.end_date|date:'Y-n-d' }}', format:'yyyy-MM-dd', isInitValue:true
        });

        form.on('submit(demoadd)', function(data) {
            $.ajax({
			    dataType: "JSON",
			    url:data.form.action, //请求地址
			    type:"PUT",  //提交类似
			    contentType: "application/json",
			    data: JSON.stringify(data.field),  //提交参数
			    success:function(res){
				larryms.msg(res.msg,{time:350},function () {
                   parent.table.reload('demo', {}); //刷新tableid ,中括号是针对分页，刷新某一页的数据时使用
                    parent.layer.close(curIfr);
                })
			    },
	    	    error:function(response){
				    larryms.msg( response.responseText);
	    	 }});

            return false;});

    });


    </script>



{% endblock %}